﻿using System;
using System.Runtime.Serialization;
using System.Globalization;

using Fuse8.DomainFramework.Domain;
using Fuse8.DomainFramework.Common;

namespace Fuse8.DomainFramework.Exceptions
{
    /// <summary>
    /// 
    /// </summary>
    [Serializable]
    public class BusinessProcessException : NotSupportedException
    {
        #region Constructors

        /// <summary>
        /// 
        /// </summary>
        /// <param name="entityObject"></param>
        /// <param name="action"></param>
        public BusinessProcessException(IEntityObject entityObject, string action)
            : this(BuildException(entityObject, action))
        { }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="entityObject"></param>
        /// <param name="action"></param>
        /// <param name="innerException"></param>
        public BusinessProcessException(IEntityObject entityObject, string action, Exception innerException)
            : this(BuildException(entityObject, action), innerException)
        { }

        /// <summary>
        /// 
        /// </summary>
        public BusinessProcessException()
            : base()
        { }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="message"></param>
        public BusinessProcessException(string message)
            : base(message)
        { }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="message"></param>
        /// <param name="innerException"></param>
        public BusinessProcessException(string message, Exception innerException)
            : base(message, innerException)
        { }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="info"></param>
        /// <param name="context"></param>
        protected BusinessProcessException(SerializationInfo info, StreamingContext context)
            : base(info, context)
        { } 

        #endregion

        /// <summary>
        /// 
        /// </summary>
        /// <param name="entityObject"></param>
        /// <param name="action"></param>
        /// <returns></returns>
        private static string BuildException(IEntityObject entityObject, string action)
        {
            Guard.ArgumentNotNull(entityObject, "entityObject");

            return string.Format(CultureInfo.InvariantCulture, "Cannot {0} entity {1}", action, entityObject.TypeParameter);
        }
    }
}
